import {dateToString} from './utl'


export function getStorageObj (key) {
  let json = localStorage.getItem(key)
  if(json){
    json = JSON.parse(json)
  }
  return json
}

//每日更新数据
export function updateDayStorageObj (key, value, force) {
  let curDate = dateToString(new Date())
  if(!force && curDate == getUpdateDate(key)){
    return
  }
  setTimeout(()=>{
    localStorage.setItem(key, JSON.stringify(value))
    setUpdateDate(key, curDate)
  }, 100)
}

//每日更新数据
export function updateStorageObj (key, value) {
  setTimeout(()=>{
    localStorage.setItem(key, JSON.stringify(value))
  }, 100)
}


export function getUpdateDate (key) {
  return localStorage.getItem( key + 'UpdateDate')
}

export function setUpdateDate (key, value) {
  return localStorage.setItem( key + 'UpdateDate', value)
}
